<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/public/inc/tags.jsp"%>
<html>
<head>
    <jsp:include page="/public/inc/head.jsp"/>
</head>
<body>
<div id="header" class="navbar navbar-static-top" role="navigation">
    <jsp:include page="/public/inc/top.jsp"/>
</div>
<div class="container-fluid" style="margin-top:5px;margin-bottom:60px;">
    <div class="row">
        <jsp:include page="/public/inc/menu.jsp"/>
        <div class="col-xs-12 col-sm-10">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <div class="media">
                        <div class="media-body">
                            <span class="glyphicon glyphicon-list"></span>兑换码
                        </div>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="form-inline">
                        <form action="/system/wwdx_cdkey/list">
                            <label>
                                <select id="merchant_id" name="merchant_id" class="form-control">
                                    <option value="">商户</option>
                                </select>
                            </label>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <label>
                                <select name="status" class="form-control">
                                    <option value="">状态</option>
                                    <option value="1" <c:if test="${model.status eq 1}">selected</c:if>>已兑换</option>
                                    <option value="0" <c:if test="${model.status eq 0}">selected</c:if>>未兑换</option>
                                </select>
                            </label>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="text" class="form-control" name="cdkey" placeholder="兑换码"/>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="submit" class="btn btn-primary">筛选</button>
                        </form>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>商户名称</th>
                            <th>产品名称</th>
                            <th>用户</th>
                            <th>兑换码</th>
                            <th>产品类型</th>
                            <th>是否兑换</th>
                            <th>创建时间</th>
                            <th>兑换时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="l" items="${list}" varStatus="status">
                            <tr>
                                <td>
                                        ${status.index + 1}
                                </td>
                                <td>
                                        ${l.merchantName}
                                </td>
                                <td>
                                        ${l.productName}
                                </td>
                                <td>
                                        ${l.userName}
                                </td>
                                <td>
                                        ${l.cdkey}
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${l.type eq 1 }">
                                            <span class="btn btn-danger btn-xs">主题包</span>
                                        </c:when>
                                        <c:when test="${l.type eq 7 }">
                                            <span class="btn btn-success btn-xs">会员卡</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="btn btn-warning btn-xs">书籍</span>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${l.status eq 1 }">
                                            <span class="btn btn-primary btn-xs">是</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="btn btn-danger btn-xs">否</span>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                        <fmt:formatDate value="${l.gmt_created}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                </td>
                                <td>
                                        <fmt:formatDate value="${l.exchange_time}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
                <div class="panel-footer">
                    <p:pagination url="/system/wwdx_cdkey/list" total="${listSize}"/>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="/public/inc/bottom.jsp"/>
</body>
</html>
<script type="text/javascript">
    $(document).ready(function () {
        /**
         * 商户列表
         */
        $.ajax({
            url: "/system/wwdx_merchant/list/json",
            dataType: "json",
            success: function (data) {
                var merchantId = document.getElementById("merchant_id");
                $.each(data.data, function (index, obj) {
                    //item.options.length = 0;清除所有option值
                    merchantId[index + 1] = new Option(obj.merchant_name, obj.id);
                    if ('${model.merchant_id}' === obj.id){
                        merchantId[0] = new Option("商户", "", true, true);
                        merchantId[index + 1] = new Option(obj.merchant_name, obj.id, true, true);
                    }
                });
            },
            error: function (data) {
                alert(data.message);
            }
        });
    });
</script>